package com.campus.web.controller.management;


import com.campus.app.service.CheckClasssService;
import com.campus.commons.entity.CheckClass;
import com.campus.commons.entity.User;
import com.campus.commons.utils.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 查班表 前端控制器
 * </p>
 *
 * @author Rin
 * @since 2020-12-24
 */
@RestController
@RequestMapping("/checkClass")
public class CheckClassController {
    @Autowired
    private CheckClasssService checkClasssService;

    /**
     * 查询所有分页
     *
     *
     * @return
     */
    @RequestMapping("/all")
    public Result<List<CheckClass>> getAll(int page, int limit) {
        Result<List<CheckClass>> checkClass = checkClasssService.getCheckClass(page, limit);
        return checkClass;
    }

    /**
     * 复合查询
     *
     * @param start
     * @param end

     * @return
     */
    @RequestMapping("/allDate")
    public Result<List<CheckClass>> getAllByDate(@RequestParam(required = true) String start, @RequestParam(required = true) String end, int page, int limit, @RequestParam(required = true) String className, @RequestParam(defaultValue = "100") int formalWork) {
        Result<List<CheckClass>> checkClassByDate = checkClasssService.getCheckClassByDate(start, end, page, limit, className, formalWork);
        return checkClassByDate;
    }

    /**
     * 查询标红的班级
     * @param work
     * @param
     * @return
     */
    @RequestMapping("/IsRed")
    public Result<List<CheckClass>>getRed(Integer work, int page, int limit) {
        Result<List<CheckClass>> checkClassByRed = checkClasssService.getCheckClassByRed(work, page, limit);
  
        return checkClassByRed;
    }

    /**
     * 删除一条查班记录
     * @param id
     *
     * @return
     */
    @PostMapping("/delete")
    Result Delete(Integer id) {
        Result del = checkClasssService.del(id);
        return del;
    }

    /**
     * 修改方法
     * @param checkClass
     * @return
     */
    @PostMapping("/update")
    Result Update( CheckClass checkClass) {
        Result result = checkClasssService.upDate(checkClass);
        return result;
    }


    //<editor-fold desc="操作缓存">
    @ApiOperation("添加查班缓存信息")
    @PostMapping("/addCache")
    public Result addCacheMap(CheckClass checkMorningExercise) {
        return checkClasssService.addCheckClassMap(checkMorningExercise);
    }
    @ApiOperation("删除查班缓存")
    @PostMapping("/delCache")
    public Result deleteCacheMap(String classroomName) {
        return checkClasssService.delCheckClassMap(classroomName);
    }
    @ApiOperation("更新查班缓存")
    @PostMapping("/upCache")
    public Result updateCacheMap(CheckClass checkMorningExercise) {
        return checkClasssService.upCheckClassMap(checkMorningExercise);

    }
    @ApiOperation("获取查班缓存")
    @PostMapping("/getCache")
    public Result getCacheMap() {
        return checkClasssService.getCacheMap();
    }
    //</editor-fold>

}

